#!/usr/bin/env perl -w

use Text::Markdown; 

# turn on auto-flushing
$cfh = select (STDOUT);
$| = 1;
select ($cfh);

sub process {
  return Text::Markdown::markdown($_[0]);
}

until(eof(STDIN)) {
  my ($length_bytes,$length,$data,$return);

  read STDIN,$length_bytes,4; # four-byte length-header
  $length=unpack("N",$length_bytes);

  read STDIN,$data,$length;

  $return=&process($data);

  print STDOUT pack("N",length($return));
  print STDOUT $return;
}